package com.atguigu.gmall.product.service.impl;

import com.alibaba.fastjson.JSON;
import com.atguigu.gmall.product.vo.ValueSkuJsonVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.gmall.product.entity.SpuSaleAttr;
import com.atguigu.gmall.product.service.SpuSaleAttrService;
import com.atguigu.gmall.product.mapper.SpuSaleAttrMapper;
import org.aspectj.weaver.ast.Var;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 *
 */
@Service
public class SpuSaleAttrServiceImpl extends ServiceImpl<SpuSaleAttrMapper, SpuSaleAttr>
    implements SpuSaleAttrService{

    @Override
    public List<SpuSaleAttr> spuSaleAttrListBySpuId(Long spuId) {
        List<SpuSaleAttr> spuSaleAttrs = baseMapper.spuSaleAttrListBySpuId(spuId);
        return spuSaleAttrs;
    }

    @Override
    public List<SpuSaleAttr> getSpuSaleAttrs(Long spuId,Long skuId) {
        List<SpuSaleAttr> spuSaleAttrs = baseMapper.getSpuSaleAttrs(spuId,skuId);
        return spuSaleAttrs;
    }

    @Override
    public String getValueSkuJson(Long spuId) {
        List<ValueSkuJsonVo> list = baseMapper.getValueSkuJson(spuId);
        Map<String, Long> map = list.stream().collect(Collectors.toMap(item -> item.getValueJson(),
                item -> item.getSkuId()));
        String jsonString = JSON.toJSONString(map);
        return jsonString;
    }
}




